﻿/// <reference path="RequestHandler.js" />
/// <reference path="../HttpRequest.js" />
/// <reference path="../../utilities/FXDom.js" />
/// <reference path="../../utilities/Markup.js" />
///--------------------------------------------------------------------
/// <file name="AdministerThreadHandler.js">
///   Adds markup buttons to the open/close/move thread pages.
/// </file>
///--------------------------------------------------------------------

NAMFox.ns(function() { with (NAMFox) {

this.AdministerThreadHandler = function() {
};

AdministerThreadHandler.prototype = new RequestHandler();
AdministerThreadHandler.prototype.name = "AdministerThreadHandler";

AdministerThreadHandler.prototype.handleRequestCore = function(request, _$) {
    /// <summary>Handles a request.</summary>
    /// <param name="request" type="HttpRequest">
    ///   The HTTP request which encapsulates the
    ///   document and route data for this request.
    /// </param>

    var textArea = _$("textarea[name=pst_body]");

    if (textArea.length === 1) {
        request.htmlDocument.__namfox__.textArea = textArea;

        if (
            !$.endsWith(request.htmlDocument.location.href, "neoseeker.com/forums/index.php") &&
            !textArea.val()
        ) {
            if ($.contains(request.htmlDocument.location.href, "move_thread")) {
                var that = this;
                function cookieCrumbReceived(cookieCrumbMarkup) {
                    textArea.val("Moved from " + cookieCrumbMarkup);
                }

                QuickMove.getCookieCrumbMarkup(request.htmlDocument, cookieCrumbReceived);
            }
            else {
                textArea.val($.messages.getDefaultMessage().text);
            }
        }

        textArea.after(
            '<div id="namfox-administer-thread-markup"></div>'
        ).find(
            "#namfox-administer-thread-markup"
        ).append(
            Markup.create(
                textArea,
                MarkupLocation.AdministerThread,
                Markup.bold,
                Markup.italics,
                Markup.underline,
                Markup.quote,
                Markup.linkName,
                Markup.anchor,
                Markup.superscript,
                Markup.subscript,
                Markup.privateMessageLink,
                Markup.replace,
                Markup.videos,
                Markup.customMessages
            )
        );
    }
};

}});